From 77c01bba24c0896565834398a689896bcdd33ebe Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Sun, 6 Feb 2011 16:54:01 +0000 Subject: [PATCH] amd iommu: Fix a xen crash after pci-attach pci-detach triggers IO page table deallocation if the last passthru device has been removed from pdev list, and this will result a BUG on amd systems for next pci-attach. This patch fixes this issue. Signed-off-by: Wei Wang --- xen/drivers/passthrough/amd/pci_amd_iommu.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/xen/drivers/passthrough/amd/pci_amd_iommu.c b/xen/drivers/passthrough/amd/pci_amd_iommu.c index 6a79efedb8..200ee2ea27 100644 --- a/xen/drivers/passthrough/amd/pci_amd_iommu.c +++ b/xen/drivers/passthrough/amd/pci_amd_iommu.c @@ -301,6 +301,11 @@ static int reassign_device( struct domain *source, struct domain *target, if ( target->max_pages > 0 ) t->paging_mode = get_paging_mode(target->max_pages); + /* IO page tables might be destroyed after pci-detach the last device + * In this case, we have to re-allocate root table for next pci-attach.*/ + if ( t->root_table == NULL ) + allocate_domain_resources(t); + amd_iommu_setup_domain_device(target, iommu, bdf); AMD_IOMMU_DEBUG("Re-assign %02x:%02x.%x from domain %d to domain %d\n", bus, PCI_SLOT(devfn), PCI_FUNC(devfn), -- 2.30.2